package com.linkage.lcims.base.dao.business.impl;

import java.util.ArrayList;
import java.util.List;

import com.linkage.lcims.base.dao.HibernateBaseDAOImpl;
import com.linkage.lcims.base.dao.business.interfaces.GroupAuthorDAO;
import com.linkage.lcims.base.po.business.BdGroupAuthor;
import com.linkage.util.exception.DAOException;

/**
 * @author Owner
 * @date 2008-1-7 TODO To change the template for this generated type comment go
 *       to Window - Preferences - Java - Code Style - Code Templates
 * @version 1.0
 */
public class GroupAuthorDAOImpl extends HibernateBaseDAOImpl implements
		GroupAuthorDAO {

	public int deleteGroupAuthor(Integer groupid) throws DAOException {
		try {
			StringBuffer sql = new StringBuffer();
			sql.append("delete BD_GROUP_AUTHOR where groupid=").append(groupid);
			return this.deleteBySql(sql.toString());
		} catch (Exception e) {
			throw new DAOException(e, this.getClass());
		}
	}

	public void saveGroupAuthor(BdGroupAuthor groupAuthor) throws DAOException {
		this.save(groupAuthor);
	}

	@SuppressWarnings("unchecked")
	public List getAuthorById(Integer groupid, Integer recordid)
			throws DAOException {
		String hql = "from BdGroupAuthor where groupid=" + groupid
				+ " and recordid=" + recordid;
		List list = this.query(hql);
		if (list.size() == 0) {
			list = new ArrayList();
		}
		return list;
	}

	public BdGroupAuthor getAuthorById(BdGroupAuthor author)
			throws DAOException {

		return (BdGroupAuthor) this.getByID(BdGroupAuthor.class, author
				.getComp_id());
	}

	public void deleteAuthor(Integer groupid, Integer recordid)
			throws DAOException {
		String hql = "delete from BdGroupAuthor where groupid=" + groupid
				+ " and recordid=" + recordid;
		this.delete(hql);
	}

	@SuppressWarnings("unchecked")
	public List<BdGroupAuthor> getAll() throws DAOException {
		return super.getAll(BdGroupAuthor.class);
	}
}
